<!-- 订单中心 -->
<template>
	<view class="order">
		<home :clickColorIndex="2"></home>

		<view class="menu-container">
			<!-- 左侧菜单 -->
			<!-- <view class="menu-sidebar"> -->
			<view class="menu-left">
				<view class="menu-title">
					订单中心
				</view>
				<view class="left-menu">
					<view v-for="(item, index) in menuItems" :key="index" :class="{ active: index === activeMenu }"
						@click="activeMenu = index">
						{{ item }}
					</view>
				</view>
			</view>
			<!-- </view> -->
			<!-- 右侧内容区（根据菜单切换显示） -->
			<view class="right-content">
				<view v-if="activeMenu === 0">
					<view v-if="!isOpenOrderDetails">
						<view class="right-title">
							<!-- 顶部Tab栏 -->
							<view class="tab-container">
								<view v-for="(tab, idx) in tabList" :key="idx" :class="{ active: activeTab === idx }"
									@click="activeTabFun(idx)">
									{{ tab.name }}
								</view>
							</view>
							<view class="search-box">
								<input type="text" placeholder="请输入商品名称/订单编号" v-model="searchVal" />
								<text class="iconfont icon-sousuo search-icon" @click="search"></text>
							</view>

						</view>

						<!-- 订单列表 -->

						<view class="order-table">
							<uni-table class="sticky-table" :loading="loading" border emptyText="快去下单吧">
								<uni-tr>
									<!-- <uni-th width="100" align="center">产品图片</uni-th>
									<uni-th width="100" align="center">产品名称</uni-th> -->
									<uni-th align="center" width="400px">产品信息</uni-th>
									<!-- <uni-th align="center" width="100px">订单编号</uni-th> -->
									<uni-th align="center" width="80px">交易状态</uni-th>
									<uni-th align="center" width="100px">收货人</uni-th>
									<uni-th align="center" width="100px">订单金额</uni-th>
									<uni-th align="center" width="100px">操作</uni-th>
								</uni-tr>
								<template v-for="(orderLi,orderIndex) in tableData" :key="orderIndex">
									<uni-tr class="orderLi">
										<uni-td colspan="10">
											<view class="orderView">
												<text>创建订单时间：{{msToDateTime(orderLi.create_date)}}</text>
												<text>订单编号：{{orderLi.order_no}}</text>
												<!-- <text class="count-down">剩余等待时间：{{ countdown }}</text> -->
											</view>
										</uni-td>
									</uni-tr>
									<uni-tr>
										<uni-td align="center">
											<!-- <view class="information" v-for="(paramLi, paramIndex) in item.param":key="paramIndex"> -->
											<view class="information" v-for="(item, index) in orderLi.goods.cartList"
												:key="index">
												<view class="td-img">
													<image :src="item.param.image?item.param.image:item.goods_image"
														mode="aspectFill"></image>
												</view>
												<view class="introduce">
													<view class="introduce-name">{{item.goods_title}}</view>
													<view class="introduce-name">{{item.param.model}}</view>
													<view class="introduce-model">产品型号：{{item.param.specs}}</view>
												</view>
												<view class="introduceN">
													<view class="introduce-model">x{{item.param.number}}</view>
												</view>
											</view>
										</uni-td>


										<!-- <uni-td align="center">{{orderLi.order_no}}</uni-td> -->
										<uni-td align="center">
											<label v-if="orderLi.status[orderLi.status.length-1].code==0"
												style="color:#ff5500">
												{{orderLi.status[orderLi.status.length-1].text}}
											</label>

											<label
												v-if="orderLi.status[orderLi.status.length-1].code==1 || orderLi.status[orderLi.status.length-1].code==2 || orderLi.status[orderLi.status.length-1].code==3 || orderLi.status[orderLi.status.length-1].code==7"
												style="color: #00c250">
												{{orderLi.status[orderLi.status.length-1].text}}
											</label>

											<label
												v-if="orderLi.status[orderLi.status.length-1].code==4 || orderLi.status[orderLi.status.length-1].code==5 || orderLi.status[orderLi.status.length-1].code==6 || orderLi.status[orderLi.status.length-1].code==8"
												style="color: #999">
												{{orderLi.status[orderLi.status.length-1].text}}
											</label>

										</uni-td>
										<uni-td align="center">{{orderLi.address.name}}</uni-td>
										<uni-td align="center">￥{{orderLi.pay_total_price}}</uni-td>
										<uni-td align="center">
											<view class="uni-group">
												<button class="uni-button" v-show="orderLi.status_code==0" size="mini"
													@click="payNow(orderLi)">立即支付</button>
												<button class="uni-button" v-show="orderLi.status_code==2" size="mini"
													type="default" @click="openpopupTake(orderLi)">确认收货</button>
												<button class="uni-button"
													v-show="orderLi.status_code==0||orderLi.status_code==1" size="mini"
													@click="orderToggle(orderLi,orderIndex)">取消订单</button>
												<button class="uni-button" v-show="orderLi.status_code==1" size="mini"
													type="default" @click="openPopup(orderLi)">提醒发货</button>
												<button class="uni-button" size="mini" type="default"
													@click="openOrderDetails(orderLi)">订单详情</button>
												<button class="uni-button"
													v-show="orderLi.status_code==2 || orderLi.status_code==3 || orderLi.status_code==7"
													size="mini" type="default"
													@click="openLogisticsPopup(orderLi)">查看物流</button>
												<button class="uni-button"
													v-show="orderLi.status_code==0||orderLi.status_code==1" size="mini"
													type="default" @click="ressModal(orderLi)">修改地址</button>
												<button class="uni-button"
													v-show="(orderLi.status_code==3||orderLi.status_code==7)&& !orderLi.is_invoice"
													size="mini" type="warn"
													@click="openinvoiceInfo(orderLi)">申请开票</button>
												<button class="uni-button"
													v-show="(orderLi.status_code==3||orderLi.status_code==7)&& orderLi.is_invoice"
													size="mini" type="warn"
													@click="download_invoice(orderLi)">下载发票</button>
												<!-- <button class="uni-button" size="mini" type="default"
													@click="openEval(orderLi)">评价</button> -->
											</view>
										</uni-td>
									</uni-tr>
								</template>

							</uni-table>
							<!-- </scroll-view> -->
							<!-- <view v-if="loading" class="loading">加载中...</view> -->
							<!-- <view v-if="noMoreData" class="no-more-data">没有更多数据了</view> -->
						</view>
						<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize"
								:current="pageCurrent" :total="total" @change="change" /></view>
					</view>

					<!-- 订单详情 -->
					<orderDetails @back="backFun" v-if="isOpenOrderDetails" :orderData="orderDataObj"></orderDetails>

				</view>

				<!-- 售后订单 -->
				<view v-if="activeMenu === 1">
					<view v-if="!isSalesDetails">
						<view class="right-title">
							<!-- 顶部Tab栏 -->
							<view class="tab-container">
								<view v-for="(tab, idx) in salesList" :key="idx" :class="{ active: salesTab === idx }"
									@click="salesTab = idx">
									{{ tab.name }} ({{ tab.count }})
								</view>
							</view>
							<view class="search-box">
								<input type="text" placeholder="请输入商品名称/订单编号" v-model="salesVal" />
								<text class="iconfont icon-sousuo search-icon"></text>
							</view>

						</view>

						<!-- 售后订单列表 -->
						<view class="order-table">
							<uni-table class="sticky-table" :loading="salesLoading" border emptyText="暂无售后申请">
								<uni-tr>
									<uni-th align="center" width="400px">产品信息</uni-th>
									<uni-th align="center" width="100px">数量</uni-th>
									<uni-th align="center" width="100px">退款金额</uni-th>
									<uni-th align="center" width="100px">申请时间</uni-th>
									<uni-th align="center" width="100px">服务类型</uni-th>
									<uni-th align="center" width="100px">退款状态</uni-th>
									<uni-th align="center" width="100px">售后状态</uni-th>
									<uni-th align="center" width="100px">操作</uni-th>
								</uni-tr>
								<template v-for="(salesLi,salesIndex) in 3" :key="salesIndex">
									<uni-tr class="orderLi">
										<uni-td colspan="10">
											<view class="orderView">
												<text>订单编号：LB15250529006</text>
												<text>退款编号：LB15250529006</text>
											</view>
										</uni-td>
									</uni-tr>
									<uni-tr>
										<uni-td align="center">
											<view class="information" v-for="(item, index) in salesTableData"
												:key="index">
												<view class="td-img">
													<image src="/static/carousel04.png" mode="aspectFill"></image>
												</view>
												<view class="introduce">
													<view class="introduce-name">聚合物真零级涡旋半波片，m=1，工作波长633 nm，通光孔径21.5
														mm，双层衬底，安装于标准SM1透镜套筒中</view>
													<view class="introduce-model">产品型号：VR1-633</view>
												</view>
											</view>
										</uni-td>
										<uni-td align="center">1</uni-td>
										<uni-td align="center">￥2245</uni-td>
										<uni-td align="center">2025-05-29 08:49:09</uni-td>
										<uni-td align="center">退货退款</uni-td>
										<uni-td align="center">退款成功</uni-td>
										<uni-td align="center">已完成</uni-td>
										<uni-td align="center">
											<view class="uni-group">
												<!-- 
												退货退款：1、
												 -->
												<!-- 传参共用一个物流组件 -->
												<button class="uni-button" size="mini" type="default"
													@click="openLogisticsPopup('售后查看物流')">查看物流</button>
												<button class="uni-button" size="mini" type="warn"
													@click="inputDialogToggle">撤销申请</button>

												<button class="uni-button" size="mini" type="default"
													@click="openExchangeReturn(1)">提交退货</button>
												<button class="uni-button" size="mini" type="default"
													@click="openExchangeReturn(0)">提交换货</button>
												<button class="uni-button" size="mini" type="default"
													@click="openLogisticsPopup">确认收货</button>
												<button class="uni-button" size="mini" type="default"
													@click="afterSalesDetails">查看详情</button>
												<!-- <button class="uni-button" size="mini" type="warn"
													@click="inputDialogToggle">退单详情</button>
												<button class="uni-button" size="mini" type="warn"
													@click="inputDialogToggle">换货详情</button> -->
											</view>
										</uni-td>
									</uni-tr>
								</template>

							</uni-table>
						</view>
						<view class="uni-pagination-box"><uni-pagination show-icon :page-size="salesPageSize"
								:current="salesPageCurrent" :total="salesTotal" @change="change" /></view>
					</view>

					<!-- 售后详情 -->
					<salesDetails @salesDack="backSalesDetails" v-if="isSalesDetails"></salesDetails>
				</view>
				<!-- <view v-if="activeMenu === 2">定制订单内容</view> -->
				<!-- <view v-if="activeMenu === 3">我的钱包内容</view> -->
			</view>
			<!--取消订单弹窗-->
			<uni-popup ref="orderinputDialog">
				<uni-popup-dialog class="popup-dialog" type="center" cancelText="取消" confirmText="确认" title="取消原因"
					@confirm="orderConfirm" @close="orderClose" :before-close="true">
					<view class="popup-content">
						<uni-data-select :localdata="cancellationOrderRange" @change="orderChange"></uni-data-select>
					</view>
				</uni-popup-dialog>
			</uni-popup>

			<!--取消售后弹窗-->
			<uni-popup ref="inputDialog">
				<uni-popup-dialog class="popup-dialog" type="center" cancelText="取消" confirmText="确认" title="撤销原因"
					@confirm="dialogConfirm" @close="dialogClose">
					<view class="popup-content">
						<uni-data-select :localdata="revocationApplication"
							@change="cancellationOrderChange"></uni-data-select>
					</view>
				</uni-popup-dialog>
			</uni-popup>
			<!--提醒发货弹窗-->
			<uni-popup ref="popup" type="center">
				<view class="popup-box">
					<text class="title">提醒发货</text>
					<text class="desc">提醒发货成功，仓库人员正在积极备货中，请耐心等待。</text>
					<uni-button class="confirm-btn" @click="closePopup">知道了</uni-button>
				</view>
			</uni-popup>
			<!--确认收货弹窗-->
			<uni-popup ref="popupTake" type="center">
				<view class="popup-box">
					<text class="title">确认收货</text>
					<text class="desc1">确认收到货了吗？</text>
					<text class="desc descSize">为了保障售后权益，请检查后在确认收货。</text>
					<view class="button-group">
						<button class="btn cancel" @click="closepopupTake">取消</button>
						<button class="btn confirm" @click="confirmTake">确定</button>
					</view>
				</view>
			</uni-popup>
			<!-- 修改地址弹窗 -->
			<modifyAddress :addressData="addressData" @addressUpdated="sureressModal" ref="addressModal">
			</modifyAddress>
			<!-- 查看物流弹窗 -->
			<logisticsPopup ref="logisticsModal"></logisticsPopup>
			<!-- 修改开票弹窗 -->
			<invoiceInfoPopup :unitInvoice="unitInvoice" :invoiceData="invoiceData" @invoiceInfo="invoiceInfoFun"
				ref="invoiceInfo"></invoiceInfoPopup>
			<!-- 评价弹窗 -->
			<evaluationPopup ref="eval"></evaluationPopup>
			<!--提交退换货弹窗-->
			<uni-popup ref="exchangeReturn" type="center">
				<view class="exchange">
					<text class="title">确认信息</text>
					<uni-forms ref="exchangeForm" :modelValue="exchangeFormData">
						<uni-forms-item label="退货方式">
							<view class="doorPickup">上门取件</view>
						</uni-forms-item>
						<uni-forms-item label="上门时间">
							<uni-data-picker placeholder="请选择取件时间" popup-title="请选择取件时间" :localdata="dataTree"
								v-model="exchangeFormData.classes">
							</uni-data-picker>
						</uni-forms-item>
						<uni-forms-item label="取件地址">
							<uni-easyinput :disabled="wantDisable" v-model="exchangeFormData.pickAddress"
								:suffixIcon="wantDisable?'compose':'checkmarkempty'" @iconClick="iconClick"
								placeholder="请输入取件地址" />
						</uni-forms-item>
						<uni-forms-item label="商家地址">
							<uni-easyinput :disabled="false" v-model="exchangeFormData.merchant" @iconClick="iconClick"
								placeholder="请输入取件地址" />
						</uni-forms-item>
					</uni-forms>
					<view class="button-group">
						<button class="btn cancel" @click="closeExchangeReturn">取消</button>
						<button class="btn confirm" @click="closeExchangeReturn">确定</button>
					</view>
				</view>
			</uni-popup>
			<!-- 立即支付 -->
			<!-- <uni-popup ref="paymentLayer" type="center">
				<view class="paymentSty">
					<uni-icons type="closeempty" size="20" class="paymentSty-icon" @click="paymentClose"></uni-icons>
					<payment :orderDataObj="orderDataObj" orderPage="orderPage"></payment>
				</view>
			</uni-popup> -->
		</view>
		<guarantee></guarantee>
		<footing></footing>
		<menu-tool></menu-tool>
	</view>
</template>

<script>
	const order = uniCloud.importObject('order', {
		customUI: true
	})
	var global = uniCloud.importObject('global', {
		customUI: true
	});
	export default {
		name: "order",
		data() {
			return {
				invoiceCloud: null,
				currentCancelIndex: null,
				routes: [{
						to: "/pages/index/index",
						name: "首页",
					},
					{
						to: "",
						name: "菜单 A",
					},
					{
						to: "",
						name: "菜单 B",
					},
				],
				// menuItems: ['订单管理', '售后订单', '定制订单', '我的钱包'],
				menuItems: ['订单管理'],
				activeMenu: 0, // 初始选中第一个菜单


				// 订单管理
				activeTab: 0, // 当前选中的Tab索引
				tabList: [{
						name: '全部订单',
						count: 2, // 数据条数
						type: 'all'
					},
					{
						name: '待付款',
						count: 3,
						type: 'unpaid'
					},
					{
						name: '待发货',
						count: 3,
						type: 'unshipped'
					},
					{
						name: '待收货',
						count: 3,
						type: 'undelivered'
					},
					{
						name: '已完成',
						count: 3,
						type: 'completed'
					}
				],
				orderDataObj: {}, // 当前要处理的订单数据
				// 表格
				searchVal: '', // 搜索的内容
				loading: false,
				tableData: [], // 全部
				status_code: undefined, // 默认全部
				pendingPaymentList: [], //待付款
				// beShipped: [], //已支付(待发货)
				// shipped: [], // 已发货（待收货）
				// received: [], //已收货（已完成）
				// 分页
				pageSize: 10,
				pageCurrent: 1, // 当前页数
				total: 0,
				// noMoreData: false, // 是否没有更多数据
				// containerHeight: 530, // 当前视口高度
				// scrollBottomOffset: 50, // 距离底部多少距离时触发加载更多
				unitInvoice: [], //  单位发票列表
				invoiceData: [], //  个人发票列表

				// 取消订单
				// cancellationOrderVal: '', // 原因
				cancel_text: '', // 取消原因
				cancellationOrderRange: [{
						value: 0,
						text: "信息填写错误"
					},
					{
						value: 1,
						text: "买错了"
					},
					{
						value: 2,
						text: "其它"
					},
				], // 取消原因数据
				revocationApplication: [{
						value: 0,
						text: "不想退货了"
					},
					{
						value: 1,
						text: "快递员无法揽收，要求取消"
					},
					{
						value: 2,
						text: "更换其它退货方式"
					},
					{
						value: 2,
						text: "快递员超时未揽收"
					},
					{
						value: 2,
						text: "取件时间或地址错误"
					},
					{
						value: 2,
						text: "其它原因"
					},
				], // 取消原因数据
				isOpenOrderDetails: false, // 是否显示订单详情


				totalSeconds: 3 * 24 * 60 * 60 + 0 * 60 * 60 + 0 * 60 + 0,
				countdown: '',
				addressData: {}, // 修改地址



				// 售后订单
				isSalesDetails: false, // 是否显示售后订单详情
				salesTab: 0, // 当前选中的Tab索引
				salesList: [{
						name: '全部订单',
						count: 2, // 数据条数
						type: 'all'
					},
					{
						name: '待付款',
						count: 3,
						type: 'unpaid'
					},
					{
						name: '待发货',
						count: 3,
						type: 'unshipped'
					},
					{
						name: '待收货',
						count: 3,
						type: 'undelivered'
					},
					{
						name: '已完成',
						count: 3,
						type: 'completed'
					}
				],
				// 表格
				salesVal: '', // 搜索的内容
				salesLoading: false,
				salesTableData: [],
				// 分页
				salesPageSize: 4,
				salesPageCurrent: 1, // 当前页数
				salesTotal: 0,

				// 取消订单
				salesOrderVal: '', // 原因
				salesOrderRange: [{
						value: 0,
						text: "信息填写错误"
					},
					{
						value: 1,
						text: "买错了"
					},
					{
						value: 2,
						text: "其它"
					},
				], // 取消原因数据
				classes: '1-2',
				dataTree: [],
				exchangeFormData: {
					classes: '', // 上门时间
					pickAddress: '', // 取件
					merchant: '' // 商家地址
				},
				wantDisable: true,
				orderNo: '', // 订单id
			}
		},
		onLoad(option) {
			console.log(option); //打印出上个页面传递的参数。
			if (option._id) {
				this.orderNo = option._id
			}
		},
		mounted() {
			if (!uni.getStorageSync('login-userinfo')._id) {
				uni.showToast({
					title: '请先登录',
					icon: 'none'
				});
				uni.navigateTo({
					url: '/pages/login/login'
				});
				return;
			} else {}
			this.invoiceCloud = uniCloud.importObject('invoice');
			// this.startCountdown();
			this.getOrderData(this.pageCurrent)
		},
		methods: {
			getOrderData(pageCurrent) { // pageCurrent 当前页 searchVal 搜索内容

				const uid = uni.getStorageSync('login-userinfo')._id
				console.log('uid::', uid);
				order.getOrderList(
					uid, {
						page: pageCurrent, // 当前页
						// pageSize: 4, // 每页条数
						status_code: this.status_code, // 订单状态
						searchVal: this.searchVal // 搜索内容
					},
				).then((data) => {
					console.log('获取订单数据:', data)
					this.tableData = data.list; // 列表数据
					this.total = data.pagination.total; // 数据总条数

					if (this.orderNo) {
						console.log('asda：：', this.tableData)
						console.log('orderNo：：', this.orderNo)
						this.tableData.find(item => {
							if (item.order_no === this.orderNo) {
								this.orderDataObj = item;
								this.isOpenOrderDetails = true;
							}
						})
					}
					// 0:未支付，1：已支付，2:已发货，3：已收货，4：申请退款，5：已退款，6：已取消，7：已评价

				}).catch((e) => {
					uni.showToast({
						title: '获取数据列表失败',
						icon: 'none'
					});
					// console.log('订单取消失败', e.message)
				})
			},

			// 分页触发
			change(e) {
				this.getOrderData(e.current)
			},

			msToDateTime(input) {
				const date = new Date(input); // 初始化Date对象，支持毫秒数或ISO格式字符串
				if (isNaN(date.getTime())) { // 检查日期是否有效
					throw new Error('无效的时间输入，请提供毫秒数或ISO格式时间字符串');
				}
				const padZero = (num) => num.toString().padStart(2, '0'); //补零函数：确保月份/日期/时分秒为两位数（如1→01）

				const year = date.getFullYear();
				const month = padZero(date.getMonth() + 1);
				const day = padZero(date.getDate());
				const hour = padZero(date.getHours());
				const minute = padZero(date.getMinutes());
				const second = padZero(date.getSeconds());

				// 4. 拼接格式
				return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
			},
			activeTabFun(idx) {
				this.activeTab = idx
				// this.getOrderData(1,) // 0:未支付，1：已支付，2:已发货，3：已收货，4：申请退款，5：已退款，6：已取消，7：已评价
				if (this.tabList[idx].name === '全部订单') {
					this.status_code = undefined
				} else if (this.tabList[idx].name === '待付款') {
					this.status_code = 0
				} else if (this.tabList[idx].name === '待发货') {
					this.status_code = 1
				} else if (this.tabList[idx].name === '待收货') {
					this.status_code = 2
				} else if (this.tabList[idx].name === '已完成') {
					this.status_code = 3
				} else {
					console.log("请检查订单状态")
				}
				this.getOrderData(1)
			},

			// 取消订单弹窗
			orderToggle(item, index) {
				this.orderDataObj = item;
				this.currentCancelIndex = index;
				this.$refs.orderinputDialog.open()
			},

			orderChange(e) { // 取消订单原因
				this.cancel_text = this.salesOrderRange[e].text
			},
			orderConfirm(val) { // 确认取消订单
				console.log(val)
				if (!this.cancel_text) {
					uni.showToast({
						title: '请选择取消原因',
						icon: 'none'
					})
					return;
				}
				//取消订单
				const a = this.cancelOrder(this.orderDataObj.order_no, this.cancel_text);
				console.log(a);
				this.$refs.orderinputDialog.close()
			},
			//取消订单
			cancelOrder(order_no, text) {
				var index = this.currentCancelIndex;
				uni.showLoading({
					title: '订单取消中'
				})
				order.cancelOrder(order_no, text).then(res => {
					uni.hideLoading()
					if (res.code == 203) { //调起退款
						this.tableData[index].status.push({
							code: 5,
							text: '已退款',
							create_date: new Date().getTime()
						});
						this.tableData[index].status_code = 5;
					} else if (res.code == 201) {
						this.tableData[index].status.push({
							code: 6,
							text: '已取消',
							create_date: new Date().getTime()
						});
						this.tableData[index].status_code = 6;
					} else if (res.code == 202) {
						this.tableData[index].status.push({
							code: 8,
							text: '退款审核中',
							create_date: new Date().getTime()
						});
						this.tableData[index].status_code = 8;
					}
				}).catch(err => {
					console.log('取消失败', err);
				});
			},
			orderClose() { //取消
				console.log("取消了")
				this.cancel_text = '';
				this.$refs.orderinputDialog.close()
			},

			// cancelOrder() { // 取消支付订单
			// 	order.updateOrder(
			// 		this.orderDataObj.order_no, {
			// 			status: {
			// 				code: 6,
			// 				text: '已取消',
			// 				cancel_text: this.cancel_text // 取消原因
			// 			}
			// 		},
			// 	).then((data) => {
			// 		console.log('订单已取消:', data)
			// 		this.getOrderData(this.pageCurrent) // 更新列表
			// 		uni.showToast({
			// 			title: '订单已取消',
			// 			icon: 'none'
			// 		});
			// 	}).catch((e) => {
			// 		uni.showToast({
			// 			title: '订单取消失败',
			// 			icon: 'none'
			// 		});
			// 	})
			// },

			payNow(item) {
				console.log('item：', item)
				this.orderDataObj = item;
				
				uni.setStorage({
					key: 'orderData',
					data: this.orderDataObj,
					success: function() {
					}
				});
				uni.redirectTo({
					url: '/pages/shopping_payment/shopping_payment'
				});
				// this.$refs.paymentLayer.open();
			},
			// paymentClose() {
			// 	this.$refs.paymentLayer.close();
			// },


			// 打开确认收货弹窗
			openpopupTake(item) {
				this.orderDataObj = item;
				this.$refs.popupTake.open();
			},
			// 确认收货弹窗
			confirmTake(item) {
				this.confirmReceipt()
				this.$refs.popupTake.close();
			},
			// 关闭收货弹窗
			closepopupTake() {
				this.$refs.popupTake.close();
			},
			confirmReceipt() {
				this.cancel_text = '';
				order.updateOrder(
					this.orderDataObj.order_no, {
						status: {
							code: 3,
							text: '已完成'
						}
					},
				).then((data) => {
					console.log('已收货，已完成:', data)
					this.getOrderData(this.pageCurrent) // 更新列表
					uni.showToast({
						title: '已收货',
						icon: 'none'
					});
				}).catch((e) => {
					uni.showToast({
						title: '收货失败',
						icon: 'none'
					});
				})
			},
			// 打开提醒发货弹窗
			openPopup(item) {
				this.orderDataObj = item;
				this.cancel_text = '';
				order.updateOrder(
					this.orderDataObj.order_no, {
						is_urge: this.orderDataObj.is_urge ? this.orderDataObj.is_urge + 1 : 1
					},
				).then((data) => {
					console.log('已提醒发货:', data)
					this.$refs.popup.open();
					this.getOrderData(this.pageCurrent) // 更新列表
					// uni.showToast({
					// 	title: '已提醒并催促发货人员',
					// 	icon: 'none'
					// });
				}).catch((e) => {})
			},
			// 关闭提醒发货弹窗
			closePopup() {
				this.$refs.popup.close();
			},

			// 打开修改地址弹窗
			ressModal(item) {
				console.log(item);
				this.orderDataObj = item;
				this.addressData = item.address
				this.$refs.addressModal.openModal(this.addressData)
			},
			sureressModal(item) {
				console.log(item);
				order.updateOrder(
					this.orderDataObj.order_no, {
						address: item
					},
				).then((data) => {
					console.log('更改地址1:', data)
					this.getOrderData(this.pageCurrent) // 更新列表
					// uni.showToast({
					// 	title: '地址修改成功',
					// 	icon: 'none',
					// 	duration:2000
					// })
				}).catch((e) => {})
			},


			// 打开修改发票弹窗
			openinvoiceInfo(item) {
				this.orderDataObj = item;
				this.$refs.invoiceInfo.openinvoiceInfo();
				// this.getInvoiceList();
			},
			// 获取发票信息
			// async getInvoiceList() {

			// 	const uid = uni.getStorageSync('login-userinfo')._id
			// 	try {
			// 		const res = await this.invoiceCloud.getList({
			// 			page: 1,
			// 			size: 50,
			// 			// type: 1 // 可选，筛选类型 1:公司 2:个人
			// 		}, uid)
			// 		if (res.success) {
			// 			const invoiceList = res.data.list
			// 			this.unitInvoice = invoiceList.filter(item => item.type === 1); // 单位发票数据
			// 			this.invoiceData = invoiceList.filter(item => item.type === 2); // 个人发票数据
			// 			console.log('单位：', this.unitInvoice)
			// 			console.log('个人：', this.invoiceData)
			// 		}
			// 	} catch (e) {
			// 		uni.showToast({
			// 			title: e.message || '获取列表失败',
			// 			icon: 'none'
			// 		})
			// 	}
			// },
			invoiceInfoFun(val) { // 发票传递过来的数据
				console.log(val)
				order.updateOrder(
					this.orderDataObj.order_no, {
						is_invoice: true,
						invoice: val.invoice,
						'invoice.notes': val.remark
					},
				).then((data) => {
					console.log('已申请开票:', data)
					this.getOrderData(this.pageCurrent) // 更新列表
					uni.showToast({
						title: '已申请开票',
						icon: 'none'
					});
				}).catch((e) => {
					uni.showToast({
						title: '申请开票失败',
						icon: 'none'
					});
				})
			},

			// 打开评价弹窗
			openEval() {
				this.$refs.eval.open();
			},
			// 返回订单详情
			backFun() {
				if (this.orderNo) {
					uni.navigateTo({
						url: '/pages/order/order'
					})
				} else {
					this.isOpenOrderDetails = false;
				}
			},

			// 订单详情
			openOrderDetails(item) {
				console.log(item)
				this.orderDataObj = item;
				this.isOpenOrderDetails = true;
			},
			download_invoice(item) {
				const url = item.invoice.url;
				console.log(url)
				if (!url) {
					uni.showToast({
						title: '请通知客服上传发票文件',
						icon: 'none'
					})
					return;
				}
				const a = document.createElement('a')
				a.href = url
				// 从URL中提取文件名
				const fileName = url.split('/').pop().split('?')[0]
				a.download = fileName
				document.body.appendChild(a)
				a.click()
				document.body.removeChild(a)

				uni.showToast({
					title: '文件开始下载',
					icon: 'none'
				})
			},
			// 搜索
			search() {
				this.getOrderData(this.pageCurrent)
			},













			// 取消订单弹窗
			inputDialogToggle() {
				this.$refs.inputDialog.open()
			},
			cancellationOrderChange(e) { // 测回售后原因
				console.log("e:", e);
				this.cancel_text = this.salesOrderRange[e]
			},




			// 确定撤销
			dialogConfirm() {

			},
			// 取消撤销
			dialogClose() {},
			// startCountdown() {
			// 	const timer = setInterval(() => {
			// 		if (this.totalSeconds > 0) {
			// 			this.totalSeconds--;
			// 			const days = Math.floor(this.totalSeconds / (24 * 60 * 60)).toString().padStart(2, '0');
			// 			const hours = Math.floor((this.totalSeconds % (24 * 60 * 60)) / 3600).toString().padStart(
			// 				2, '0');
			// 			const minutes = Math.floor((this.totalSeconds % 3600) / 60).toString().padStart(2, '0');
			// 			const seconds = (this.totalSeconds % 60).toString().padStart(2, '0');
			// 			this.countdown = `${days}天${hours}时${minutes}分${seconds}秒`;
			// 		} else {
			// 			clearInterval(timer);
			// 			this.countdown = '时间已到';
			// 		}
			// 	}, 1000);
			// },
			// 返回售后详情
			backSalesDetails() {
				this.isSalesDetails = false;
			},
			// 打开售后详情
			afterSalesDetails() {
				this.isSalesDetails = true;
			},
			// 打开退换货弹窗
			openExchangeReturn(val) {
				this.$refs.exchangeReturn.open();
			},
			// 关闭退换货弹窗
			closeExchangeReturn(val) {
				this.$refs.exchangeReturn.close();
			},

			// 查看物流
			openLogisticsPopup(val) {
				console.log(val)
				this.$refs.logisticsModal.openPopup(val)
			},







			iconClick(type) {
				console.log(type)
				uni.showToast({
					title: `点击了${type==='prefix'?'左侧':'右侧'}的图标`,
					icon: 'none'
				});

				this.wantDisable = !this.wantDisable;
			}
		}
	};
</script>

<style scoped>
	.order {
		width: 100%;
		min-height: 100%;
		background-color: #F5F5F5;
	}

	/* 左侧菜单 */
	.menu-container {
		display: flex;
		margin-left: 40px;
		width: 1400px;
		/* height: 100vh; */
		margin: 30px auto 0;
	}

	.menu-sidebar {
		width: 220px;
		height: 800px;
	}

	.menu-left {
		width: 220px;
		height: 800px;
		background: #FFF;
		border-radius: 10px;
		position: sticky;
		top: 90px;
	}

	.left-menu {
		width: 100%;
		padding: 20px 0;
		box-sizing: border-box;
		font-size: 14px;
		text-align: center;
	}

	.left-menu view {
		/* padding: 15px; */
		/* width: 100px; */
		width: 100%;
		/* height: 30px; */
		height: 60px;
		line-height: 60px;
		margin: 0 auto;
		/* margin-bottom: 10px; */
		/* border-radius: 15px; */
		cursor: pointer;
		transition: background 0.3s;
	}

	.left-menu .active {
		/* background: #f3a73f; */
		background: rgb(250, 240, 226);
		border-right: 3px solid rgb(240, 209, 168);
		/* color: #FFF; */
		text-align: center;
		/* font-weight: bold; */
	}

	.menu-title {
		width: 100%;
		height: 50px;
		color: #fff;
		text-align: center;
		line-height: 50px;
		font-size: 18px;
		font-weight: bold;
		border-radius: 10px 10px 0 0;
		background-image: linear-gradient(to right, #e60012, #f3a73f);
	}

	/* 右侧内容 */
	.right-content {
		width: 1200px;
		/* max-height: 2800px; */
		padding: 10px 20px;
		box-sizing: border-box;
		background: #fff;
		margin-left: 20px;
		border-radius: 10px;
	}

	.right-title {
		width: 100%;
		min-height: 50px;
		border-radius: 25px;
		/* background: #f3a73f; */
		background-image: linear-gradient(45deg, #e60012, #f3a73f);
		color: #41250e;
		padding: 0 5px 0 15px;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		margin-bottom: 20px;
		border-bottom: 2px solid #e60012;
	}

	/* 订单 */

	.tab-container {
		width: 100%;
		display: flex;
	}

	.tab-container view {
		padding: 5px 10px;
		cursor: pointer;
		font-size: 14px;
		color: #FFF;
	}

	.tab-container .active {
		color: red;
		background-color: rgb(250, 240, 226);
		font-weight: 600;
		border-radius: 15px;
	}

	.search-box {
		/* width: 200px; */
		display: flex;
		align-items: center;
		border: 1px solid #e5e5e5;
		background-color: #FFF;
		border-radius: 20px;
		padding: 5px 15px;
	}

	.search-box input {
		width: 200px;
		border: none;
		font-size: 14px;
	}

	.search-icon {
		width: 18px;
		height: 18px;
		margin-left: 10px;
		cursor: pointer;
	}

	/* 订单 */
	.order-table {
		/* border: 1px solid #e5e5e5; */
		/* height: 660px; */
		/* max-height: 2820px; */
		border-radius: 8px;
		/* overflow: hidden; */
		/* overflow-y: auto; */
		margin-bottom: 20px;
	}

	.sticky-table {
		display: table;
		width: 100%;
		/* height: 300px; */
	}

	.sticky-table /deep/ .uni-table-loading {
		/* display: none; */
	}

	.orderLi {
		background-color: #f0f0f0;
	}

	.orderView {
		height: 38px;
		line-height: 38px;
		padding: 0 16px;
		box-sizing: border-box;
	}

	.orderView text {
		padding-right: 60px;
	}

	.orderView .count-down {
		color: #c6231d;
	}

	.information {
		display: flex;
		border-bottom: 1px #EBEEF5 solid;
		padding: 8px 10px;
	}

	.information:last-child {
		border-bottom: 0 #EBEEF5 solid;
	}

	.uni-table-td {
		padding: 0;
	}

	.introduce {
		width: 400px;
		text-align: left;
		margin-left: 30px;
	}

	.introduceN {
		width: 20px;
		text-align: left;
		margin-left: 30px;
	}

	.introduce-name {}

	.introduce-model {
		padding-top: 20px;
	}

	.td-img {
		width: 100px;
		height: 100px;
		/* margin: auto; */
		margin-left: 20px;
	}

	.td-img image {
		width: 100%;
		height: 100%;
	}

	/* 表格 */
	.uni-group {
		display: flex;
		flex-flow: column;
		align-items: center;
		padding: 10px 0;
	}

	.uni-button {
		margin-top: 10px;
	}

	.uni-button:nth-child(1) {
		margin-top: 0;
	}

	/* 取消订单弹窗 */
	.popup-content {
		/* @include flex;	 */
		width: 400px;
		height: 40px;
		align-items: center;
		justify-content: center;
		padding: 15px;
		background-color: #fff;
	}

	.popup-dialog /deep/ .uni-dialog-title {
		display: flex;
		flex-direction: row;
		line-height: 46px;
		padding-left: 37px;
		background: #e5e5e5;
		border-radius: 11px 11px 0 0;
		justify-content: left;
		padding-top: 0;
	}

	.popup-dialog /deep/ .uni-popup__error {
		color: #333;
	}

	.popup-dialog /deep/ .uni-select__selector-item {
		color: #999;
	}

	.popup-dialog /deep/ .uni-dialog-button {
		cursor: pointer;
	}

	/* 提醒发货弹窗 */
	.popup-box {
		width: 300px;
		/* 弹窗宽度 */
		padding: 20px;
		background-color: #fff;
		border-radius: 8px;
		box-sizing: border-box;
		overflow: hidden;
	}

	.exchange {
		width: 500px;
		/* 弹窗宽度 */
		padding: 20px;
		background-color: #fff;
		border-radius: 8px;
		box-sizing: border-box;
		/* overflow: hidden; */
	}

	.title {
		font-size: 15px;
		font-weight: bold;
		margin-bottom: 15px;
		display: block;
	}

	.doorPickup {
		margin-top: 8px;
		color: #666;
	}

	.desc {
		font-size: 14px;
		color: #666;
		line-height: 1.5;
		margin-bottom: 25px;
		display: block;
	}

	.desc1 {
		font-size: 14px;
		color: #333;
		line-height: 1.5;
		display: block;
	}

	.descSize {
		font-size: 12px;
		color: #999;
	}

	.confirm-btn {
		float: right;
		padding: 0 15px;
		background-color: #f5f5f5;
		color: #333;
		border-radius: 4px;
		font-size: 14px;
	}

	.button-group {
		display: flex;
		/* justify-content: space-between; */
		margin: 30px auto;
		margin-bottom: 0;
		width: 290px;
	}

	.btn {
		width: 20%;
		height: 30px;
		border-radius: 8px;
		font-size: 16px;
		line-height: 30px;
		font-size: 14px;
		/* margin-left: 60px; */
	}

	.btn.cancel {
		background: #f5f5f5;
		color: #333;
		margin-left: 120px;
		margin-right: 20px;
	}

	.btn.confirm {
		background: #E91F1B;
		color: #fff;
		margin-left: 0;
	}

	.paymentSty {
		background-color: #FFF;
		position: relative;
	}

	.paymentSty-icon {
		position: absolute;
		top: 10px;
		right: 10px;
	}
</style>